package learnjava.concur.chapter4;

import java.util.concurrent.locks.LockSupport;

/**
 * LockSupport的park和unpack实现循环打印
 */
public class P083 {


    static Thread t1, t2, t3;

    public static void main(String[] args) throws Exception{

        t1 = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                LockSupport.park();
                System.out.print("a");
                LockSupport.unpark(t2);
            }
        });

        t2 = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                LockSupport.park();
                System.out.print("b");
                LockSupport.unpark(t3);
            }
        });

        t3 = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                LockSupport.park();
                System.out.print("c");
                LockSupport.unpark(t1);
            }
        });

        t1.start();
//        LockSupport.unpark(t1);
//        Thread.sleep(1000);
        t2.start();
        t3.start();
        LockSupport.unpark(t1);
    }
}
